package com.sj.tensquare.friend.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sj.tensquare.friend.entity.FriendEntity;
import com.sj.tensquare.friend.service.FriendService;
import com.sj.common.utils.PageUtils;
import com.sj.common.utils.R;



/**
 * 
 *
 * @author sj
 * @email 1071842192@qq.com
 * @date 2020-12-02 08:56:52
 */
@RestController
@RequestMapping("friend/friend")
public class FriendController {
    @Autowired
    private FriendService friendService;

    @RequestMapping("/getFriend")
    public R userlist(){
        FriendEntity friendEntity = new FriendEntity();
        friendEntity.setFriendid("测试");
        return R.ok().put("test",Arrays.asList(friendEntity));
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = friendService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userid}")
    public R info(@PathVariable("userid") String userid){
		FriendEntity friend = friendService.getById(userid);

        return R.ok().put("friend", friend);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody FriendEntity friend){
		friendService.save(friend);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody FriendEntity friend){
		friendService.updateById(friend);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] userids){
		friendService.removeByIds(Arrays.asList(userids));

        return R.ok();
    }

}
